﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MicroDal
{
    /// <summary>
    /// Helper for creating SQL queries
    /// </summary>
    /// 
    /// DRAFT:
    internal class SqlBuilder
    {
        private Type type;

        public SqlBuilder(Type type)
        {
            this.type = type;
        }

        public string SelectAll(string where = "",string orderBy = "", int limit = 0)
        {
            return Select(where: where, orderBy: orderBy, limit: limit);
        }

        public string Select(string columns = "*", string where = "", string orderBy = "", int limit=0)
        {
            string sqlformat = ((limit > 0) ? "SELECT TOP " + limit : "SELECT") + " {0} FROM {1}";
            if (!string.IsNullOrEmpty(where))
                sqlformat += " WHERE " + where;

            if (!string.IsNullOrEmpty(orderBy))
                sqlformat += " ORDER BY " + orderBy;

            return string.Format(sqlformat, columns, type.Name);
        }
    }
}
